import { createRouter, createWebHistory } from 'vue-router'
import MainLayout from '../layouts/MainLayout.vue'

// 路由配置
const routes = [
    {
        path: '/',
        component: MainLayout,
        children: [
            {
                path: '',
                name: 'Home',
                component: () => import('../views/Home.vue'),
                meta: {
                    title: '首页'
                }
            },
            {
                path: 'contest',
                name: 'Contest',
                component: () => import('../views/Contest.vue'),
                meta: {
                    title: '比赛'
                }
            },
            {
                path: 'problems',
                name: 'Problems',
                component: () => import('../views/Problems.vue'),
                meta: {
                    title: '题库'
                }
            },
            {
                path: 'discuss',
                name: 'Discuss',
                component: () => import('../views/Discuss.vue'),
                meta: {
                    title: '讨论'
                }
            },
            {
                path: 'records',
                name: 'Records',
                component: () => import('../views/Records.vue'),
                meta: {
                    title: '评测记录'
                }
            },
            {
                path: 'subject',
                name: 'Subject',
                component: () => import('../views/subject.vue'),
                meta: {
                    title: '学科'
                }

            }
        ]
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import('../views/Login.vue'),
        meta: {
            title: '登录'
        }
    },
    {
        path: '/register',
        name: 'Register',
        component: () => import('../views/Register.vue'),
        meta: {
            title: '注册'
        }
    }
]

// 创建路由实例
const router = createRouter({
    history: createWebHistory(),
    routes
})

// 路由守卫：设置页面标题
router.beforeEach((to, from, next) => {
    document.title = `${to.meta.title} - ThinkOJ`
    next()
})

export default router 